import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:pd_application/pages/home/index.dart';
import 'package:pd_application/pages/login.dart';
import 'package:pd_application/pages/not_found.dart';
import 'package:pd_application/pages/order/order.dart';
import 'package:pd_application/pages/register.dart';

class Routes {
  // static const String HOME = '/';
  // ignore: non_constant_identifier_names
  static String HOME = '/';
  // ignore: non_constant_identifier_names

  // ignore: non_constant_identifier_names
  static String LOGIN = '/login';
  // ignore: non_constant_identifier_names
  static String REGISTER = '/register';
  // ignore: non_constant_identifier_names
  static String ORDER = '/order/:title';

  //定义路由处理函数
  // ignore: prefer_final_fields
  static Handler _homeHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return const HomePage();
  });
  // ignore: prefer_final_fields
  static Handler _loginHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return const LoginPage();
  });
  // ignore: prefer_final_fields
  static Handler _registerHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return const RegisterPage();
  });
  // ignore: prefer_final_fields
  static Handler _orderHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return OrderPage(
      params['title']![0],
    );
  });
  // ignore: prefer_final_fields
  static Handler _notFoundHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return const NotFoundPage();
  });
  // 编写configureRoutes关联路由和处理函数
  static void configureRoutes(FluroRouter router) {
    router.define(HOME, handler: _homeHandler);
    router.define(LOGIN, handler: _loginHandler);
    router.define(REGISTER, handler: _registerHandler);
    router.define(ORDER, handler: _orderHandler);
    router.notFoundHandler = _notFoundHandler;
  }
}
